package com.fast.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.fast.common.service.impl.FastWrapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


/**
 * Class MyBaseMapper
 *
 * @Auther: lhy
 * @Date: 2021/11/22 18:09
 * @Mail: 190643201@qq.com
 */
public interface FastBaseMapper<T> extends BaseMapper<T> {

    String SQL1 = "select" +
            "<if test='ew.sqlSelect != null'>" +
            "${ew.sqlSelect}" +
            "</if>" +
            "<if test='ew.sqlSelect == null'>" +
            " * " +
            "</if>" +
            "from " +
            "${masterTable} " +
            "${sqlSegment} " +
            "${ew.customSqlSegment}";

    String SQL2 = "select * from ${masterTable} ${sqlSegment}";

    @Select(SQL2)
    List<Map<String, Object>> query(String masterTable, String sqlSegment);

    @Select("<script>" + SQL1 + "</script>")
    List<Map<String, Object>> queryWrapper(String masterTable, String sqlSegment, @Param(Constants.WRAPPER) FastWrapper<T> wrapper);

    @Select(SQL2)
    IPage<Map<String, Object>> pageQuery(IPage<T> page, String masterTable, String sqlSegment);

    @Select("<script>" + SQL1 + "</script>")
    IPage<Map<String, Object>> pageQueryWrapper(IPage<T> page, String masterTable, String sqlSegment, @Param(Constants.WRAPPER) FastWrapper<T> fastWrapper);

    @Select(SQL2+" limit 1")
    Map<String, Object> find(String masterTable, String sqlSegment);

    @Select("<script>" + SQL1 + " limit 1 </script>")
    Map<String, Object> findWrapper(String masterTable, String sqlSegment, @Param(Constants.WRAPPER) FastWrapper<T> fastWrapper);
}
